package com.coocaa.app.lib.cleaner.scanner.scannerother;

import android.content.Context;
import android.util.Log;

import com.coocaa.app.lib.cleaner.mgr.DataHolder;
import com.coocaa.app.lib.cleaner.scanner.AbstractScanner;
import com.coocaa.app.lib.cleaner.scanner.config.ConfigManagerFactory;
import com.coocaa.app.lib.cleaner.scanner.scannerother.data.OtherData;

import java.util.List;
import java.util.Set;

/**
 * Created by Eric on 2017/4/12.
 */

public class OtherScanner implements AbstractScanner {
    private Context mContext = null;
    private DataHolder mDataHolder = null;
    private OtherUtils ou = null;

    @Override
    public void setDataHolder(Context context, DataHolder holder) {
        mContext = context;
        mDataHolder = holder;
        ou = new OtherUtils(mContext);
    }

    @Override
    public void stop() {
        ou.stopScan();
    }

    @Override
    public void run() {
        Log.d("oscan", "OtherScanner run");
        OtherData data = ou.getOtherData();
        if (data != null && mDataHolder != null) {
//            mDataHolder.appendOtherData(data.list,data.length);
            if (data.list != null && data.list.size() > 0) {
                for (String path : data.list) {
                    Log.d("oscan", "OtherScanner path:" + path + "  " + data.length);
                    mDataHolder.appendOtherData(path);
                }
            }
            //追加的deleteFile
            List<String> delList = ConfigManagerFactory.factory.instance().load().getFileDelFiles();
            if (delList != null && delList.size() > 0) {
                Set<String> tempList = mDataHolder.getOtherData().datas.keySet();
                for (String path : delList) {
                    if (tempList != null && tempList.size() > 0 && tempList.contains(path))
                        continue;
                    Log.d("oscan", "OtherScanner adddelete path:" + path + "  " + data.length);
                    mDataHolder.appendOtherData(path);
                }
            }
        }

    }
}
